package org.telluriumsource.ui.widget.dojo.object;

import demo.tellurium.framework.BaseDojoWidget 

import org.json.simple.JSONObject;

/**
 * Tellurium Widget object for the Dojo TooltipDialogTextBox widget
 *
 * @author Roger Xu (roger.xu.2007@gmail.com)
 *
 * Date: Apr 14, 2010
 * 
 */
class TooltipDialogTextBox extends BaseDojoWidget {

    private static final String WIDGET_NAME = TooltipDialogTextBox.class.getSimpleName();

    private String widgetId = null;

    @Override
    public String getWidgetName() {
        return WIDGET_NAME;
    }

    @Override
    public JSONObject toJSON() {
        return buildJSON() {jso ->
            jso.put(UI_TYPE, NAMESPACE + "_" + getWidgetName());
        }
    }

    @Override
    public void defineWidget() {
        ui.Container(uid: "${WIDGET_NAME}") {
            Container(uid: "TextBox", clocator: [tag: "div", class: "dijitTextBox", widgetid: "${widgetId}"], respond: ["click"]) {
                Container(uid: "InputField", clocator: [tag: "div", class: "dijitInputField"]) {
                    InputBox(uid: "InputTextBox", clocator: [tag: "input", type: "text"])
                }
            }
            Container(uid: "TooltipDialog", clocator: [tag: "div", widgetid: "dlg_${widgetId}"]) {
                List(uid: "Options", clocator: [tag: "table"], separator: "tbody:visible") {
                    Container(uid: "{all}", clocator: [tag: "div", class: "dijitCheckBox"]) {
                        CheckBox(uid: "CheckBox", clocator: [:])
                    }
                }
            }
        }
    }

    public void clickTextBox() {
        def textbox = "${WIDGET_NAME}.TextBox";
        click textbox
    }

    public String getValue() {
        def textbox = "${WIDGET_NAME}.TextBox";
        def inputTextBox = "${textbox}.InputField.InputTextBox";
        return getValue(inputTextBox);
    }

    public void selectItem(int index) {
        // click option list
        def listUid = "${WIDGET_NAME}.TooltipDialog.Options";
        if (!isElementPresent(listUid)) {
            console.debug("not show", listUid);
            return;
        }

        clickListOption(listUid, "CheckBox", index);
    }
}